package com.stockz.core.manager;

import java.util.Collection;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.stockz.core.dao.BarDao;
import com.stockz.core.model.Bar;

@Service
@Transactional
public class BarManager{
	
	@Autowired
	private BarDao barDao;
	
	@Transactional(propagation=Propagation.REQUIRES_NEW)
	public void persist(Bar bar) {
		barDao.persist(bar);
	}

	@Transactional(propagation=Propagation.REQUIRES_NEW)
	public <T extends Collection<? extends Bar>> void persistAll(T barCollection) {
		barDao.persistAll(barCollection);
	}

	@Transactional(propagation=Propagation.REQUIRES_NEW, readOnly=true)
	public Date getMaxBarDate() {
		return barDao.getMaxBarDate();
	}
	
	@Transactional(propagation=Propagation.REQUIRES_NEW, readOnly=true)
	public List<Bar> getBarList(String code) {
		return barDao.getBarList(code);
	}

	@Transactional(propagation=Propagation.REQUIRES_NEW, readOnly=true)
	public List<Bar> getBarList(String code, int maxCount) {
		return barDao.getBarList(code, maxCount);
	}
	
}
